<?php

	function recursive_chmod ($foldername, $dir_mode, $file_mode) {
		$dh = opendir($foldername);
 
		while ( $entry = readdir($dh) ) {
			if ( '' != $entry && '.' != $entry && '..' != $entry ) {
				$_entry = $foldername . '/' . $entry;
 
				if ( false === is_dir($_entry) ) {
					chmod ( $_entry, $file_mode );
				}
 
				if ( true === is_dir($_entry) ) {
					recursive_chmod ($_entry, $dir_mode, $file_mode);
				}
			}
		}

		closedir($dh);
		chmod($foldername, $dir_mode);
	}
  
?>